package com.ramos.kuaixiao.utils;

import android.content.Context;

import java.lang.Thread.UncaughtExceptionHandler;

public class CrashHandler implements UncaughtExceptionHandler {

	private static CrashHandler mHandler;
	
	private Context mContext;
	
	private CrashHandler(Context context){
		mContext = context;
	}
	
	public static CrashHandler getInstance(Context context){
		
		if(null == mHandler){
			synchronized (CrashHandler.class) {
				if(null == mHandler){
					mHandler = new CrashHandler(context);
				}
			}
		}
		return mHandler;
	}
	
	@Override
	public void uncaughtException(Thread thread, Throwable ex) {
		String exLog = CommUtil.getStackTrace(ex);
		CommUtil.d(mContext, "CrashHandler", exLog);
		FileUtil.saveCrashLog(exLog);
		android.os.Process.killProcess(android.os.Process.myPid());
	}
}
